/**
 * NetworkManager.java
 * ************************** 
 * @date Mar 23, 2011
 * @author Michele Tamburini
 * 
 * **************************
 */
package networkRmi;

import infrastructureAPI.Service;

import java.net.InetAddress;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import messages.Message;
import messages.MessageHandler;


/**
 * Description:
 * A NetworkManager gives the ability to send and receive Messages
 * through the Java RMI protocol.
 * A service that needs to receive Messages has to register through a 
 * class implementing the NetworkManager and provide a MessageHandler.
 * The MessageHandler has to be able to dispatch the Messages 
 * related with the service (see the {@code MessageHandler} interface).
 * A NetworkManager gives also direct access to the net by the call 
 * of send(Message m, InetAddress host), which is a remote call toward the 
 * 'host' machine.  
 *
 */
public interface NetworkManager extends Service {
	
	/**
	 * In order to receive Messages from a remote host, 
	 * a service need to register to a NetworkManager.
	 * With the call of this function it also has to provide
	 * a MessageHandler, which is a class able to dispatch and 
	 * collect the Messages related to the registered service
	 * from the overall.
	 *  
	 * @param handler : MessageHandler
	 */
	public void registerService(MessageHandler handler);
	
	/**
	 * @param handler
	 */
	void deRegisterService(MessageHandler handler);
	
	/**
	 * Returns the name of the node.
	 * 
	 * @return nodeName : String
	 */
	public String getNodeName();
	
	/**
	 * Sends the Message 'msg' to the machine identified by 'destHost'.
	 * It's a remote call so the RemoteException and additionally also
	 * NotBoundException have to be managed.
	 * 
	 * @param msg
	 * @param destHost
	 * @throws NotBoundException 
	 */
	void send(Message msg, InetAddress destHost) throws RemoteException, NotBoundException;
	
	boolean ping(InetAddress node, String service) throws RemoteException, NotBoundException;
	
	//TODO
	/**
	 *
	 * @param address
	 * @param service
	 */
//	void contactRemoteService(InetAddress address, String service) throws RemoteException, NotBoundException;

}
